Python SDK Getting Started
#
InstallTo use the python SDK it is nessecary to install it using PIP:
pip install ZEVIT-AIH-SDK
#
ConnectOnce installed, a connection to the desired environment can be established using the 'AIHClient':
from AIH_SDK import AIHClient
client = AIHClient(environment, client_id, client_secret)
Here 'environment' could e.g. be 'zevit-dev'.
#
GETNow objects can be retrieved. It is possible to retrieve all the instances, but also to specify a specific instance by 'guid' as follows:
from AIH_SDK.Assets import MainSystem, Plant
mainsystems = MainSystem().get()plant = Plant().get('12345678-1234-1234-1234-123456789012')
#
View objectTo view the object, the json value of the object can be accessed by the 'value' attribute. The object can however also be viewed as a pandas.DataFrame:
plant_json = plant.value
plant_df = plant.to_dataframe()
#
Update values and PUTTo update some values of the object, the 'update_values(...)' method can be used. This however only changes the values in the 'valute' attribute. To send the changes to the database, use the 'put()' method.
plant.update_values( { 'name' : 'some new name', 'address__street1' : 'some new streetname' }).put()
It can here be seen that 'put()' is applied directly after the 'update_values(...)' as chaining is possible. The use of double underscore (__) is to access nested values.
#
New object and POSTTo create a new object and post it to the database, a similar approach can be used. But a better approach than 'update_values(...)', is the 'from_dict(...)' method as it makes sure that 'value' of the object is overridden and not updated.
plant_new = Plant().from_dict( { 'name' : 'some new name', 'address' : { ... }, ... }).post()
The 'plant_new' variable now holds the created object which includes the id given by the backend.
#
DELETETo delete an object it is simply possible to use the 'delete()' method. The only prerequisite is that the object has an 'id' value. Otherwise the 'id' can be specified.
plant_new.delete()
Plant().delete(id_to_delete='12345678-1234-1234-1234-123456789012')